/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package queenb.web.financial.controller;

import java.text.ParseException;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import javax.faces.model.SelectItem;
import queenb.net.entitybean.T800;
import queenb.web.controller.QueenbController;
import queenb.web.financial.inteface.FinancialExpectedInf;
import queenb.web.financial.store.T800Store;
import queenb.web.util.ComboboxUtil;
import queenb.web.util.ContextUtil;
import queenb.web.util.Util;

/**
 *
 * @author Ka
 */
public class FinancialExpectedController extends QueenbController {

    private ComboboxUtil comboboxUtil;
    private int ft000;
    private int h075;
    private int fb050;
    private int pt800;
    private int fh075;
    private double tn801;
    private String tn801St;
    private String tv802;
    private Date td803;
    private Date td804;
    private String td803St;
    private String td804St;
    private String tv805;
    private String tv806;
    private String tv807;
    private String tv808;
    private int tn809;
    private int fv500;
    private int fh000;
    private int fh200;
    private List<T800> listT800;
    private T800Store t800Store;
    private FinancialExpectedInf t800Inf;

    public FinancialExpectedController() {
        getKapiMenu().setAdmin(false);
        getKapiMenu().setMainmenu1("m163");
        comboboxUtil = new ComboboxUtil();
        t800Store = new T800Store();

        Object objAction = getRequest().getParameter("action");
        if (objAction != null) {
            Object objPT800 = getRequest().getParameter("pt800");
            if (objPT800 != null) {
                pt800 = Integer.parseInt(objPT800.toString());
                System.out.print("------------------"+pt800);

            }
            if (objAction.equals("edit")) {
                getListByIdT800(pt800);
            }

        }
    }

    public void getListByIdT800(int pt800) {
        try {
             System.out.println("-----pt800----" + pt800);
        List<T800> listById = getListT800();
        if (listById != null) {
            Iterator iterator = listT800.iterator();
            while (iterator.hasNext()) {
                T800 t800 = (T800) iterator.next();
                this.ft000 = t800.getFt000();
                this.fh075 = t800.getFh075();
                
                List<SelectItem> fb050Label = comboboxUtil.getListCombB050();
                for( int i =0 ; i < fb050Label.size() ; i++)
                {
                    if(t800.getBv051().equals(fb050Label.get(i).getLabel()))
                    {
                        this.fb050 = Integer.parseInt(fb050Label.get(i).getValue().toString()) ;
                        break;
                    }
                }

                this.pt800 = t800.getPt800();
                this.td803 = t800.getTd803();
                this.td804 = t800.getTd804();
                
                double tn801db = Util.convertStringToDouble(t800.getTn801St());
                tn801St = Util.numberformater(tn801db, "##,###,###");

                this.tv805 = t800.getTv805();
                this.tv806 = t800.getTv806();
                this.tv807 = t800.getTv807();
                System.out.println("-----fb050----" + t800.getFb050());
                this.tv808 = t800.getTv808();
            }
        }
        } catch (Exception e) {
        }
       
    }

    public List<SelectItem> getListCombH075() {

        return comboboxUtil.getListCombH075();
    }

    public List<SelectItem> getListCombB050() {

        return comboboxUtil.getListCombB050();
    }

    public List<SelectItem> getListCombT100() {

        return comboboxUtil.getListCombT100b();
    }

    public void updateT800() throws ParseException {
        int roweffect = 0;
        String dateStart = ContextUtil.getRequestParameter("leavedate1");
        if (!dateStart.equals("")) {
            td803 = Util.parseDate(dateStart, "dd/MM/yyyy");
        } else {
            td803 = null;
        }
        String dateEnd = ContextUtil.getRequestParameter("leavedate2");
        if (!dateEnd.equals("")) {
            td804 = Util.parseDate(dateEnd, "dd/MM/yyyy");
        } else {
            td804 = null;
        }
        System.out.println("--yyyyyyyyyyyyyyyy----" + tn801St);
        roweffect = t800Store.updateT800(
                this.getPt800(),
                this.getFh075(),
                this.getFt000(),
                Util.convertStringToDouble(tn801St),
                this.getTv802(),
                Util.toSQLDate(this.getTd803()),
                Util.toSQLDate(this.getTd804()),
                this.getTv805(),
                this.getTv806(),
                this.getTv807(),
                this.getTv808(),
                this.getTn809(),
                this.getFv500(),
                this.getFb050(),0,
                getLogin().getModule(),
                getLogin().getCompanyNo(),
                getLogin().getUserName());

        if (roweffect >= 0) {
            showGlobalReport(true, getResourceString("datasavesuccessful"));
            sendRedirect("expectedFinancial.jsp");
        } else {
            showGlobalReport(true, getResourceString("datasuccessfail"));
            sendRedirect("expectedFinancial.jsp");
        }
    }

    public List<T800> getListT800() {
        try {

            if (listT800 == null) {
                System.out.println("--list t800---" + getLogin().getModule() + ","
                        + getLogin().getCompanyNo() + ","
                        + this.getFh075() + ","
                        + this.getFt000() + ","
                        + this.getFb050() + ","
                        + this.getFv500() + ","
                        + 0 + "," + 100 + "," + 0 + "," + 1 + ","
                        + getLogin().getUserName());
                listT800 = t800Store.listT800(
                        getLogin().getModule(),
                        getLogin().getCompanyNo(),
                        this.getPt800(),
                        this.getFh075(),
                        this.getFt000(),
                        this.getFb050(),
                        this.getFv500(),
                        0, 100, 0, 1,
                        getLogin().getUserName());
            }

            return listT800;
        } catch (Exception ex) {
            return null;
        }
    }

    public void deleteT800() {
        try {
            int row = 0;
            row = t800Store.deleteT800( this.getPt800(), getLogin().getUserName());
            if (row >= 0) {
                showGlobalReport(true, getResourceString("datasavesuccessful"));
                sendRedirect("expectedFinancial.jsp");
            } else {
                showGlobalReport(true, getResourceString("datasuccessfail"));
                sendRedirect("expectedFinancial.jsp");
            }
        } catch (Exception e) {
        }
    }
    
    /**
     * @return the ft000
     */
    public int getFt000() {
        return ft000;
    }

    /**
     * @param ft000 the ft000 to set
     */
    public void setFt000(int ft000) {
        this.ft000 = ft000;
    }

    /**
     * @return the h075
     */
    public int getH075() {
        return h075;
    }

    /**
     * @param h075 the h075 to set
     */
    public void setH075(int h075) {
        this.h075 = h075;
    }

    /**
     * @return the fb050
     */
    public int getFb050() {
        return fb050;
    }

    /**
     * @param fb050 the fb050 to set
     */
    public void setFb050(int fb050) {
        this.fb050 = fb050;
    }

    /**
     * @return the pt800
     */
    public int getPt800() {
        return pt800;
    }

    /**
     * @param pt800 the pt800 to set
     */
    public void setPt800(int pt800) {
        this.pt800 = pt800;
    }

    /**
     * @return the fh075
     */
    public int getFh075() {
        return fh075;
    }

    /**
     * @param fh075 the fh075 to set
     */
    public void setFh075(int fh075) {
        this.fh075 = fh075;
    }

    /**
     * @return the tn801
     */
    public double getTn801() {
        return tn801;
    }

    /**
     * @param tn801 the tn801 to set
     */
    public void setTn801(double tn801) {
        this.tn801 = tn801;
    }

    /**
     * @return the tv802
     */
    public String getTv802() {
        return tv802;
    }

    /**
     * @param tv802 the tv802 to set
     */
    public void setTv802(String tv802) {
        this.tv802 = tv802;
    }

    /**
     * @return the td803
     */
    public Date getTd803() {
        return td803;
    }

    /**
     * @param td803 the td803 to set
     */
    public void setTd803(Date td803) {
        this.td803 = td803;
    }

    /**
     * @return the td804
     */
    public Date getTd804() {
        return td804;
    }

    /**
     * @param td804 the td804 to set
     */
    public void setTd804(Date td804) {
        this.td804 = td804;
    }

    /**
     * @return the tv805
     */
    public String getTv805() {
        return tv805;
    }

    /**
     * @param tv805 the tv805 to set
     */
    public void setTv805(String tv805) {
        this.tv805 = tv805;
    }

    /**
     * @return the tv806
     */
    public String getTv806() {
        return tv806;
    }

    /**
     * @param tv806 the tv806 to set
     */
    public void setTv806(String tv806) {
        this.tv806 = tv806;
    }

    /**
     * @return the tv807
     */
    public String getTv807() {
        return tv807;
    }

    /**
     * @param tv807 the tv807 to set
     */
    public void setTv807(String tv807) {
        this.tv807 = tv807;
    }

    /**
     * @return the tv808
     */
    public String getTv808() {
        return tv808;
    }

    /**
     * @param tv808 the tv808 to set
     */
    public void setTv808(String tv808) {
        this.tv808 = tv808;
    }

    /**
     * @return the tn809
     */
    public int getTn809() {
        return tn809;
    }

    /**
     * @param tn809 the tn809 to set
     */
    public void setTn809(int tn809) {
        this.tn809 = tn809;
    }

    /**
     * @return the fv500
     */
    public int getFv500() {
        return fv500;
    }

    /**
     * @param fv500 the fv500 to set
     */
    public void setFv500(int fv500) {
        this.fv500 = fv500;
    }

    /**
     * @return the fh000
     */
    public int getFh000() {
        return fh000;
    }

    /**
     * @param fh000 the fh000 to set
     */
    public void setFh000(int fh000) {
        this.fh000 = fh000;
    }

    /**
     * @return the fh200
     */
    public int getFh200() {
        return fh200;
    }

    /**
     * @param fh200 the fh200 to set
     */
    public void setFh200(int fh200) {
        this.fh200 = fh200;
    }

    /**
     * @return the t800Inf
     */
    public FinancialExpectedInf getT800Inf() {
        return t800Inf;
    }

    /**
     * @param t800Inf the t800Inf to set
     */
    public void setT800Inf(FinancialExpectedInf t800Inf) {
        this.t800Inf = t800Inf;
    }

    /**
     * @return the td803St
     */
    public String getTd803St() {
        return td803St;
    }

    /**
     * @param td803St the td803St to set
     */
    public void setTd803St(String td803St) {
        this.td803St = td803St;
    }

    /**
     * @return the td804St
     */
    public String getTd804St() {
        return td804St;
    }

    /**
     * @param td804St the td804St to set
     */
    public void setTd804St(String td804St) {
        this.td804St = td804St;
    }

    /**
     * @return the tn801St
     */
    public String getTn801St() {
        return tn801St;
    }

    /**
     * @param tn801St the tn801St to set
     */
    public void setTn801St(String tn801St) {
        this.tn801St = tn801St;
    }
}
